﻿@model ThesisSystem.ViewModels.Menus
<!DOCTYPE html>
<html>
<head>
    <title>头部导航</title>
    <link href="@Url.Content("~/Content/CSS/Common.css")" rel="stylesheet" type="text/css" />
    <link href="@Url.Content("~/Content/CSS/Page.css")" rel="stylesheet" type="text/css" />
    <link href="@Url.Content("~/Content/themes/base/jquery-ui.css")" rel="stylesheet" type="text/css" />
    <style type="text/css">
        .red{color:red;}
        table th,
        table td{padding:2px;}
    </style>
</head>
<body>
    <table width="800">
        <caption>菜单列表</caption>
        <tr>
            <th width="40">ID</th>
            <th width="90">标题</th>
            <th width="240">路径</th>
            <th width="40">顺序</th>
            <th width="90">上级菜单</th>
            <th width="30">学生</th>
            <th width="30">教师</th>
            <th width="46">管理员</th>
            <th width="80">备注</th>
            <th width="120"></th>
        </tr>
        <tr>
            <th colspan="10"><h3><span>顶级菜单</span> <a title="1" class="btnCreate" href="javascript:;" class="btnCreate">添加</a></h3></th>
        </tr>
        @foreach (var menu in Model.Menus1) { 
            <tr>
                <td>@menu.MenuID</td>
                <td>@menu.Title</td>
                <td>@menu.MenuUrl</td>
                <td>@if (menu.SortID == 999) { @String.Empty; }
                    else {@menu.SortID }</td>
                <td>无</td>
                <td>@if (menu.PStudent){
                        @:√
                    }
                    else { 
                        <span class="red">×</span>
                    }
                </td>
                <td>
                    @if (menu.PTeacher){
                        @:√
                    }
                    else { 
                        <span class="red">×</span>
                    }
                </td>
                <td>
                    @if(menu.PAdministrator){
                        @:√
                    }
                    else { 
                        <span class="red">×</span>
                    }
                </td>
                <td>@menu.Mark</td>
                <td>
                    <a href="javascript:;" class="btnEdit" title="@menu.MenuID">编辑</a>
                    <a href="javascript:;" class="btnDelete" title="@menu.MenuID">删除</a>
                </td>
            </tr>
        }
        <th colspan="10"><h3><span>二级菜单</span> <a title="2" class="btnCreate" href="javascript:;" class="btnCreate">添加</a></h3></th>
        @foreach (var menu in Model.Menus2) { 
            <tr>
                <td>@menu.MenuID</td>
                <td>@menu.Title</td>
                <td>@menu.MenuUrl</td>
                <td>@if (menu.SortID == 999) { @String.Empty; }
                    else {@menu.SortID }</td>
                <td>@Model.Menus1.Where(m=>m.MenuID==menu.ParentID).SingleOrDefault().Title</td>
                <td>@if (menu.PStudent)
                    {
                        @:√
                    }
                    else { 
                        <span class="red">×</span>
                    }
                </td>
                <td>
                    @if (menu.PTeacher)
                    {
                        @:√
                    }
                    else { 
                        <span class="red">×</span>
                    }
                </td>
                <td>
                    @if(menu.PAdministrator){
                        @:√
                    }
                    else { 
                        <span class="red">×</span>
                    }
                </td>
                <td>@menu.Mark</td>
                <td>
                    <a href="javascript:;" class="btnEdit" title="@menu.MenuID">编辑</a>
                    <a href="javascript:;" class="btnDelete" title="@menu.MenuID">删除</a>
                </td>
            </tr>
        }
        <th colspan="10"><h3><span>三级菜单</span> <a title="3" class="btnCreate" href="javascript:;" class="btnCreate">添加</a></h3></th>
        @foreach (var menu in Model.Menus3) { 
            <tr>
                <td>@menu.MenuID</td>
                <td>@menu.Title</td>
                <td>@menu.MenuUrl</td>
                <td>@if (menu.SortID == 999) { @String.Empty; }
                    else {@menu.SortID }</td>
                <td>@Model.Menus2.Where(m=>m.MenuID==menu.ParentID).SingleOrDefault().Title</td>
                <td>@if (menu.PStudent)
                    {
                        @:√
                    }
                    else { 
                        <span class="red">×</span>
                    }
                </td>
                <td>
                    @if (menu.PTeacher){
                        @:√
                    }
                    else { 
                        <span class="red">×</span>
                    }
                </td>
                <td>
                    @if(menu.PAdministrator){
                        @:√
                    }
                    else { 
                        <span class="red">×</span>
                    }
                </td>
                <td>@menu.Mark</td>
                <td>
                    <a href="javascript:;" class="btnEdit" title="@menu.MenuID">编辑</a>
                    <a href="javascript:;" class="btnDelete" title="@menu.MenuID">删除</a>
                </td>
            </tr>
        }
        <th colspan="10"><h3><span>四级菜单</span> <a title="4" class="btnCreate" href="javascript:;" class="btnCreate">添加</a></h3></th>
        @foreach (var menu in Model.Menus4) { 
            <tr>
                <td>@menu.MenuID</td>
                <td>@menu.Title</td>
                <td>@menu.MenuUrl</td>
                <td>@if (menu.SortID == 999) { @String.Empty; }
                    else {@menu.SortID }</td>
                <td>@Model.Menus3.Where(m=>m.MenuID==menu.ParentID).SingleOrDefault().Title</td>
                <td>@if (menu.PStudent)
                    {
                        @:√
                    }
                    else { 
                        <span class="red">×</span>
                    }
                </td>
                <td>
                    @if (menu.PTeacher){
                        @:√
                    }
                    else { 
                        <span class="red">×</span>
                    }
                </td>
                <td>
                    @if(menu.PAdministrator){
                        @:√
                    }
                    else { 
                        <span class="red">×</span>
                    }
                </td>
                <td>@menu.Mark</td>
                <td>
                    <a href="javascript:;" class="btnEdit" title="@menu.MenuID">编辑</a>
                    <a href="javascript:;" class="btnDelete" title="@menu.MenuID">删除</a>
                </td>
            </tr>
        }
    </table>
    <div id="dialog" title="添加菜单">
        <iframe src="" id="myiframe" frameborder="0" width="100%" height="96%" scrolling="no"></iframe>
    </div>
    @Content.Script("jquery-min.js", Url)
    @Content.Script("jquery-ui-min.js", Url)
    @if (false)
    {
        <script src="../../Scripts/jquery-vsdoc.js" type="text/javascript"></script>
        <script src="../../Scripts/jquery-ui-min.js" type="text/javascript"></script>
    }
    <script type="text/javascript">
        $(function () {
            
            //初始化对话框
            var dialogBox = $("#dialog");
            dialogBox.dialog({
                autoOpen: false,
                height: 370,
                width: 340,
                resizable:false,
                modal:true,
                close:function(){
                        location.reload();
                    }
            });
            $(".btnEdit").button().bind("click",function(){
                var title = "编辑菜单";
                var url = "@Url.Content("~/Menu/Edit/")" + $(this).attr("title");
                dialogBox.dialog({ title: title });
                $("#myiframe").attr("src",url);
                dialogBox.dialog("open");
            });;
            $(".btnDelete").button().bind("click",function(){
                var title = "删除菜单";
                var url = "@Url.Content("~/Menu/Delete/")" + $(this).attr("title");
                dialogBox.dialog({ title: title });
                $("#myiframe").attr("src",url);
                dialogBox.dialog("open");
            });
            $(".btnCreate").button().bind("click", function (e) {
                var title = $(e.target).parents("h3").children("span").html();
                var url = "@Url.Content("~/Menu/Create?menuLevel=")" + $(this).attr("title");
                dialogBox.dialog({ title: "添加 " + title });
                $("#myiframe").attr("src",url);
                dialogBox.dialog("open");
            });
        });
    </script>
</body>
</html>